<?php

namespace Home\Model;
use Think\Model;
class ShopModel extends CommonModel
{
    //Protected $autoCheckFields = false;


    /**
     * 由一级分类获取二级分类及其产品信息
     * int $pid 一级分类id
     * $key1 & $key2 见BaseModel方法parseSqlData()
    **/
    public function showFirstpage($pid,$key1,$key2){
        //id  img_url  title  content  jiage  sales
        $sql = "
        select a.id, a.img_url, a.title, a.content, a.jiage, a.sales, b.id as bid,b.class_name from sd_commodity as a
        inner join 
        (select id, class_name, pid from sd_classgood where pid = ". $pid .") as b
        on a.pid = b.id
        order by a.pid asc, a.id desc;
        ";
        $res = $this->sql_query($sql);
        //dump($res);
        if(!$res)
        {
            return false;
        }

        $ress = $this->parseSqlData($res, $key1, $key2);
        return $ress;
    }

    /**
     * 由商品id获取其信息
    **/
    public function getProInfoById($id)
    {
        $proInfo=M('commodity')->where('id ='.$id)->find();
        $typeid=$proInfo["youhui_typeid"];
        //查询对应的优惠券
        $coupon=M('coupon')->where('typeid='.$typeid)->find();
        $picList = M('picarr')->where('pid = "'.$id.'"')->select();
        return array('proInfo'   => $proInfo,
                      'coupn'     => $coupon,
                      'picList'   => $picList
            );
    }




}